<html>
<head><meta charset="utf-8"><title>feature descriptions · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html">feature descriptions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="234157340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234157340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael P. Jung <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234157340">(Apr 12 2021 at 13:28)</a>:</h4>
<p>As of now <code>features</code> are a simple object of the form <code>{str: [str]}</code> and optional dependencies implicitly create a new feature with the same name.</p>
<p>This has some drawbacks that I'd like to discuss:</p>
<ul>
<li>There is no way to describe a feature. Right now crates often don't document their features at all and if they do it's in an unstructured way as part of the README file. It would be nice if there was a way to add documentation to features (and optional dependencies).</li>
<li>Optional dependencies always become features even if they are only dependencies of other features.</li>
<li>Features and optional dependencies share the same namespace. Thus in order to write a feature <code>foo</code> that enables the optional dependency<code>foo</code> the dependency needs an alias. e.g. <code>foo-crate = { package = "foo", ...}</code> and the resulting feature list becomes even more convoluted. (e.g. <a href="https://docs.rs/crate/deadpool/0.7.0/features">https://docs.rs/crate/deadpool/0.7.0/features</a>, <code>config</code> enables both the <code>config-crate</code> and <code>serde</code> dependency.)</li>
</ul>
<p>I wonder if there are any plans to improve this situation. I would love to see something like that in a future version of <code>Cargo.toml</code>:</p>
<div class="codehilite" data-code-language="TOML"><pre><span></span><code><span class="k">[features.config]</span>
<span class="n">default</span> <span class="o">=</span> <span class="kc">true</span>
<span class="n">description</span> <span class="o">=</span> <span class="s">"Enable support for config crate"</span>
<span class="n">dependencies</span> <span class="o">=</span> <span class="k">["config-crate", "serde/derive"]</span>
</code></pre></div>
<p>Going one step further I wonder if it would make sense to put futures and crates into their own namespace and differentiating between crate and feature dependencies thus making it possible to have both a <code>config</code> feature and a <code>config</code> dependency at the same time. Also it would make a lot of sense if optional dependencies would not implicitly result in features but need to be made public explicitly:</p>
<div class="codehilite" data-code-language="TOML"><pre><span></span><code><span class="k">[features.serde]</span>
<span class="n">dependencies</span> <span class="o">=</span> <span class="k">["serde/derive"]</span>

<span class="k">[features.config]</span>
<span class="n">enable_features</span> <span class="o">=</span> <span class="k">["serde"]</span>
<span class="n">dependencies</span> <span class="o">=</span> <span class="k">["config"]</span>
</code></pre></div>
<p>This is something that's been bugging me for quite some time now and I started hacking <a href="http://crates.io">crates.io</a> trying to add a proper features tab to it. I had to realize that this needs to a change of the underlying <code>Cargo.toml</code> and <code>cargo</code> to be more useful than what <code>docs.rs</code> currently provides.</p>
<p>This is by no means an RFC. I'd like to hear from you what you think of this and if it's worth putting this into a proper RFC.</p>



<a name="234161806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234161806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234161806">(Apr 12 2021 at 13:52)</a>:</h4>
<p>You have described some of the problems well! There are several unstable features that are part of the solution.<br>
Mostly <a href="https://doc.rust-lang.org/cargo/reference/unstable.html#namespaced-features">https://doc.rust-lang.org/cargo/reference/unstable.html#namespaced-features</a><br>
and <a href="https://doc.rust-lang.org/cargo/reference/unstable.html#weak-dependency-features">https://doc.rust-lang.org/cargo/reference/unstable.html#weak-dependency-features</a></p>



<a name="234166573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234166573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael P. Jung <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234166573">(Apr 12 2021 at 14:17)</a>:</h4>
<p>"Namespaced features" and "Weak dependency features" solve 99% of the pain. Regarding the description of features I wonder how big the impact would be if a feature could either be written as an array of strings (the current format) or a table which allows the addition of a <code>description</code> field? This could even happen separately from the other two features as it is mostly cosmetical and doesn't change anything of the underlying resolver logic.</p>



<a name="234166879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234166879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pietro Albini <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234166879">(Apr 12 2021 at 14:19)</a>:</h4>
<p>(having a description of some sort would be great for displaying the features on <a href="http://crates.io">crates.io</a> and <a href="http://docs.rs">docs.rs</a>, cc <span class="user-mention" data-user-id="232545">@Joshua Nelson</span>)</p>



<a name="234166923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234166923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234166923">(Apr 12 2021 at 14:19)</a>:</h4>
<p>yup and separating optional dependencies from features would also be super useful</p>



<a name="234166934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234166934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234166934">(Apr 12 2021 at 14:19)</a>:</h4>
<p>right now we have to show both</p>



<a name="234468628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234468628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael P. Jung <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234468628">(Apr 14 2021 at 09:32)</a>:</h4>
<p>What's the best way to get started with this? Just write an implementation for parsing either <code>{str: [str]}</code> or <code>{str: {"description": str, "dependencies": [str]}}</code> and create a PR? Or does this need a RFC?</p>



<a name="234501384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234501384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234501384">(Apr 14 2021 at 13:47)</a>:</h4>
<p>I'm not shore. But I recall that <span class="user-mention" data-user-id="116015">@Alex Crichton</span>  was talking about a similar suggestion for a different reason. Maybe because the syntacs for features is getting prity dense. I don't remember? But however we prosed I like the idea.</p>



<a name="234509165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234509165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234509165">(Apr 14 2021 at 14:35)</a>:</h4>
<p>I think something like this should probably have an RFC.  Thanks for looking into it, let me know if you have any questions.</p>



<a name="234509391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/feature%20descriptions/near/234509391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/feature.20descriptions.html#234509391">(Apr 14 2021 at 14:36)</a>:</h4>
<p>There's an issue at <a href="https://github.com/rust-lang/cargo/issues/4956">https://github.com/rust-lang/cargo/issues/4956</a> with some comments about some of the concerns.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>